package com.ybkj.chat.module.dynamic.activity;


import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewStub;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ybkj.chat.R;
import com.ybkj.chat.base.BaseMvpActivity;
import com.ybkj.chat.manager.ActivityManager;
import com.ybkj.chat.module.dynamic.adapter.DynamicDetailAdapter;
import com.ybkj.chat.module.main.activity.LikeListActivity;
import com.ybkj.chat.ui.adapter.LikeIconAdapter;
import com.ybkj.chat.ui.dialog.PpwShare;
import com.ybkj.chat.ui.view.CircleImageView;
import com.ybkj.chat.ui.view.recyclerview.DividerItemDecoration;
import com.ybkj.chat.ui.view.recyclerview.XRecyclerView;
import com.ybkj.chat.utils.ResourcesUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 推荐话题详情（动态详情）
 */

public class DynamicDetailActivity extends BaseMvpActivity {
    @BindView(R.id.ns_root)
    NestedScrollView nestedScrollView;
    @BindView(R.id.headIv)
    CircleImageView headIv;
    @BindView(R.id.nameTv)
    TextView nameTv;
    @BindView(R.id.point_menu)
    ImageView pointMenu;
    @BindView(R.id.linkOrImgViewStub)
    ViewStub linkOrImgViewStub;
    @BindView(R.id.tv_address_or_distance)
    TextView tvAddressOrDistance;
    @BindView(R.id.like)
    TextView like;
    @BindView(R.id.xrc_like)
    RecyclerView xrcLike;
    @BindView(R.id.lastComment)
    TextView lastComment;
    @BindView(R.id.xrc_lastComment)
    XRecyclerView xrcLastComment;

    //最新评论daapter
    private DynamicDetailAdapter mDynamicDetailAdapter;
    //点赞列表adapter
    private LikeIconAdapter mLikeIconAdapter;
    private PpwShare mPpwShare;

    @Override
    protected void injectPresenter() {

    }

    @Override
    protected void initTitle() {
        setTitleText("推荐话题");

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_dynamic_detail;
    }

    @Override
    protected void initView() {
        initrecycle();
        initSharePop();
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.headIv, R.id.point_menu, R.id.linkOrImgViewStub, R.id.like_layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.headIv:
                break;
            case R.id.point_menu:
                mPpwShare.showAtLocation(nestedScrollView, Gravity.BOTTOM, 0, 0);
                mPpwShare.setBackgroundAlpha(this, 0.5f);
                break;
            case R.id.linkOrImgViewStub:
                break;
            case R.id.like_layout:
                ActivityManager.gotoActivity(mContext, LikeListActivity.class);
                break;
        }
    }

    private void initrecycle() {
        xrcLastComment.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL_LIST, 1,
                ResourcesUtil.getColor(R.color.activity_background)));
        mDynamicDetailAdapter = new DynamicDetailAdapter(mContext);
        mDynamicDetailAdapter.addData("1");
        mDynamicDetailAdapter.addData("1");
        mDynamicDetailAdapter.addData("1");
        mDynamicDetailAdapter.addData("1");
        mDynamicDetailAdapter.addData("1");
        xrcLastComment.setAdapter(mDynamicDetailAdapter);

        mLikeIconAdapter = new LikeIconAdapter(mContext);
        mLikeIconAdapter.addData("1");
        mLikeIconAdapter.addData("1");
        mLikeIconAdapter.addData("1");
        LinearLayoutManager Manager = new LinearLayoutManager(this);
        Manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        xrcLike.setLayoutManager(Manager);
        xrcLike.setAdapter(mLikeIconAdapter);
        mLikeIconAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ActivityManager.gotoActivity(mContext, LikeListActivity.class);
            }
        });
    }

    private void initSharePop() {
        mPpwShare = new PpwShare(mContext);
        mPpwShare.setOnItemClickListener(new PpwShare.OnItemClickListener() {
            @Override
            public void onItemClick(View v) {
                switch (v.getId()) {
                    case R.id.tv_cancel:
                        mPpwShare.dismiss();
                        break;

                    case R.id.tv_share:
                        mPpwShare.dismiss();

                        break;

                    case R.id.forward:
                        mPpwShare.dismiss();
                        break;
                }

            }
        });
    }
}
